var Xvfb = require("xvfb");
var xvfb = new Xvfb();
var cp = require("child_process");
cp.exec("pwd", function (err, stdout, stderr) {
    if (err) {
        return console.warn(err);
    } else {
        console.log("当前路径:",stdout);
        xvfb.start(function (err, xvfbProcess) {
            var Nightmare = require("nightmare");
            var nightmare = new Nightmare({ show: false ,});
            console.log(process.env['DISPLAY']);
            console.log(process.env["DEBUG"]);
            nightmare.goto("https://www.baidu.com/")
                .wait("form#form")
                .type("input#kw", "Hujimiya")
                .click("#su")
                .wait(".result.c-container")
                .evaluate(function () {
                    alert(window.location.href);
                    // debugger
                    return { html: document.querySelector(".result.c-container").innerHTML };
                }).then((result) => {
                    console.log(result);
                    nightmare.evaluate(() => {
                        return document.head.toString();
                    })
                        .end().then(function end(arg) {
                            debugger
                            xvfb.stop(function (err) {
                                debugger
                            })
                        })
                })
        });
    }
})




